<?php
namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;


use App\Models\ChannelModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use App\Libs\Common\CsvUtil;
use App\Logics\AnalysisLogic;
class AnalysisController extends BaseController{

    private function getInstance(){
        static $ob=null;
        if($ob===null){
            $ob=new AnalysisLogic();
        }
        return $ob;
    }

    //订单分期日对账列表
    public function orderStagesDailyBill(){
        $start_time=trim(request('start_time'));
        $end_time=trim(request('end_time'));
        $page=(int)request('page',1);
        $per_page=(int)request('per_page',20);

        $para=[
            'start_time'=>$start_time,
            'end_time'=>$end_time,
            'page'=>$page,
            'per_page'=>$per_page
        ];

        $ob=$this->getInstance();
        $data=$ob->orderStagesDailyBill($para);
        if($data && is_string($data)) die(json_error($data));


//        p($data);die;
        $content= view("admin.analysis.orderStagesDailyBill",$data) ;
        $data=[
            'content'=>$content,
            'header'=>'订单月账单',
        ];
        return  $this->baseList($data);
    }

    //订单分期日对账列表
    public function orderStagesMonthlyBill(){
        $start_time=trim(request('start_time'));
        $end_time=trim(request('end_time'));
        $page=(int)request('page',1);
        $per_page=(int)request('per_page',20);

        $para=[
            'start_time'=>$start_time,
            'end_time'=>$end_time,
            'page'=>$page,
            'per_page'=>$per_page
        ];

        $ob=$this->getInstance();
        $data=$ob->orderStagesMonthlyBill($para);
        if($data && is_string($data)) die(json_error($data));


//        p($data);die;
        $content= view("admin.analysis.orderStagesMonthlyBill",$data) ;
        $data=[
            'content'=>$content,
            'header'=>'订单租期列表',
        ];
        return  $this->baseList($data);
    }

    //订单分析
    public function orderSummary(){
        $ob=$this->getInstance();
        $data=$ob->orderSummary();
        if($data && is_string($data)) die(json_error($data));

        $content= view("admin.analysis.orderSummary",$data) ;
        $data=[
            'content'=>$content,
            'header'=>'运营报告',
        ];
        return  $this->baseList($data);
    }

}